import { Body, Controller, Delete, Get,  Post, Put } from '@nestjs/common'
import { ShopService } from './shop.service'
@Controller('shop')
export class ShopController {
    constructor(private readonly ShopService: ShopService) { }

    @Get()
    get() {
        return {
            code: 200,
            msg: "获取成功"
        }
    }

    @Post('addShop')
    async addBrand(@Body() body: any) {

        this.ShopService.addShop(body)
        return {
            code: 200,
            msg: "添加成功"
        }
    }

    @Post("getShop")
    async getBrand(@Body() body: any) {

        const { brandname, areaName, shopName } = body;
        let searchList = [];
        if (brandname) {
            searchList.push({ brandname: { $regex: brandname } });
        }
        if (areaName) {
            searchList.push({ areaName: { $regex: areaName } });
        }
        if (shopName) {
            searchList.push({ shopName: { $regex: shopName } });
        }


        let data = await this.ShopService.getShop(searchList)
        let shopCate = [{
            value: '',
            label: '请选择',
        }]

        let data2 = await this.ShopService.getShop([])
        data2.forEach(item => {
            shopCate.push({ value: item.shopName, label: item.shopName })
        })
        return {
            code: 200,
            msg: "查询成功",
            data,
            shopCate
        }
    } 

    @Put("updateShop") 
    async updateShop(@Body() body: any) {
        
        this.ShopService.updateShop(body)
        return {
            code: 200,
            msg: "修改成功" 
        } 
    }

    @Delete("deleteShop")
    async deleteShop(@Body() body: any) {
        this.ShopService.deleteShop(body)
        return {
            code: 200,
            msg: "删除成功"
        }
    }

}
